package com.zoke.daycarpool.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zoke.daycarpool.R;
import com.zoke.daycarpool.config.CarpoolConfig;
import com.zoke.daycarpool.domain.ChannelBeen;
import com.zoke.support.base.BaseObjectListAdapter;
import com.zoke.support.image.ShowImagesAdapter.AdaterListener;
import com.zoke.support.utils.ViewHolder;

/**
 * 频道列表
 * 
 * @author jack
 * 
 */
public class ChannelAdapter extends BaseObjectListAdapter {

	private AdaterListener mListener;

	public ChannelAdapter(Context context, List<? extends Object> datas) {
		super(context, datas);
	}

	public ChannelAdapter(Context context, List<? extends Object> datas,
			AdaterListener listener) {
		super(context, datas);
		this.mListener = listener;
	}

	@Override
	public View getItemView(int position, View convertView, ViewGroup parent) {
		convertView = getConvertView(convertView, R.layout.listview_chanel_item);
		final int pos = position;
		ChannelBeen been = (ChannelBeen) mDatas.get(pos);
		RelativeLayout itemContainer = ViewHolder.get(convertView,
				R.id.item_container);
		TextView mNameTv = ViewHolder.get(convertView, R.id.channel_nameTv);
		mNameTv.setText(been.getStart() + CarpoolConfig.ROADARROW
				+ been.getDest());
		TextView mNumTv = ViewHolder.get(convertView, R.id._carpool_pnum_tv);
		mNumTv.setText("此路线有" + been.getNum() + "人");
		itemContainer.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mListener != null)
					mListener.onAdapterItemClick(pos, mDatas.get(pos));
			}
		});
		return convertView;
	}
}
